from __future__ import division
from math import *
import pylab as pl
from Init_Cond import *
from numpy import *

Sat_r_RM = []
Sat_M_Mass = []
area = []
Sat_colors = []



def sat(t, M, R_Embryo, r_sync, Roche, last, Rigid_Roche):
    del moons[:]
    del Sat_r_RM[:]
    del Sat_M_Mass[:]
    del area[:]
    del Sat_colors[:]
    for i in range(last):
        if Sat_M[i] > 0.0:
            Sat_r_RM.append(Sat_r[i]/R_Mars)
            Sat_M_Mass.append(Sat_M[i])
            area.append(pi*(75.*(5.*Sat_Rad[i]/R_Mars))**2)
            Sat_colors.append('c')

    #plot a Phobos sized dot
    Sat_r_RM.append(a_Phobos/R_Mars)
    Sat_M_Mass.append(M_Phobos)
    area.append(pi*(75.*(5.*R_Phobos/R_Mars))**2)
    Sat_colors.append('k')
    #plot a Deimos sized dot
    Sat_r_RM.append(a_Deimos/R_Mars)
    Sat_M_Mass.append(M_Deimos)
    area.append(pi*(75.*(5.*R_Deimos/R_Mars))**2)
    Sat_colors.append('k')

#*~*~**~Plotting disk~**~~*~*
    fig, ax = pl.subplots()
    pl.subplots_adjust(right=.87)
    ax.axvline(x = r_sync/R_Mars, linewidth=2, color = 'm') #synchronous line
    ax.axvline(x = Roche/R_Mars, linewidth=2, color = 'g')  #RRL line
    ax.axvline(x = Rigid_Roche/R_Mars, linewidth=2, color = 'b')    #FRL line
    ax.plot(R_M, sigma, 'black', linewidth=1.5)
    ax.set_yscale('log')
    ax.set_xlim(0, 7.)   #Don't forget to change az.set_xlim in the satellite section
    ax.set_ylim(1.e0, 1.e6)
    # ticks = ax.get_yticks()/5.e5
    # ax.set_yticklabels(ticks)
    ax.tick_params(axis='y', colors='black', labelsize=18)
    ax.tick_params(axis='x', colors='black', labelsize=18)
    # ax.title('Time ~ ' + str(round(t/year)) + ' (yrs)\nMass of Disk / Initial ~ ' + str(round(sum(m)/5.e23, 6)),fontsize=22)
    ax.set_xlabel('Distance from Mars (Mars Radii)', fontsize=22)
    ax.set_ylabel('$\sigma \ \ (g/cm^2)$', color='black', fontsize=22)

#~**~*~*~~*Plotting Satellites~*~*~~*~*~*

    az = ax.twinx()
    az.set_yscale('log')
    az.scatter(Sat_r_RM, Sat_M_Mass, s = area, c=Sat_colors)
    az.set_xlim(0, 7.)
    az.set_ylim(1.e18, 1.e23)
    az.tick_params(axis='y', colors='black', labelsize=18)
    az.tick_params(axis='x', colors='black', labelsize=18)
    az.axes.get_yaxis().set_visible(True)
    az.set_ylabel('Mass of Satellite (g)', color = 'black', fontsize = 22)

#~*~*~*~~*~* Plotting x axis *~*~*~*~**~~*~~*

    ay = ax.twinx()
    ay.set_ylim(0, r_F/R_Mars/7*9)
    ay.axes.get_yaxis().set_visible(False)
    circle = pl.Circle((0,0),R_Embryo/R_Mars, color = 'r')

    fig = pl.gcf()
    fig.gca().add_artist(circle)
    fig.set_size_inches(8.0,8.0)


    pl.suptitle('Time ~ ' + str(round(t/(1.e6*year), 3)) + ' (My)\nMass of Disk / Initial ~ ' + str(round(sum(m)/1.26240826382e+23, 3)),fontsize=22)
    pl.savefig('sigma(t_' + str(t/year - (t/year)%1.0) + ')' + '.png')
    pl.close()
